<?php
/*
	首页
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','mobile','avatar','nickname'));
	$return['member']=$member;
	$return['post']=array('mobile'=>$member['mobile']?:'');
	$return['types']=$this->tousu_types;
	set_html('title','投诉建议');
	exi($return);
}
if($_RQ['op']=='submit'){
	$postdata=get_postdata();
	$data=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid'],
		'msg'=>$postdata['msg'],
		'images'=>ijson_encode($postdata['images']),
		'ordersn'=>$postdata['ordersn'],
		'mobile'=>$postdata['mobile'],
		'types'=>$postdata['types'],
		'createtime'=>TIMESTAMP,
	);
	pdo_insert('jy_weishop_feedback',$data);
	$id=pdo_insertid();
	if($totalprice>0 && !$isnopay && !$yuejiemid){
			$params=array(
					'id'=>$id,
					'title'=>'检测订单',
					'fee'=>$totalprice,
					'plugin'=>'jy_msgorder',
					//'pay_type'=>'wechat',//可选，此项作用为指定支付方式
					'no_type'=>array('hdfk'),//可选，此项作用为指定不允许使用哪种支付方式
					'back_url'=>'jy_msgorder/fuwu.book/payresult/',//必填，指定异步支付结果通知地址，采用系统标准URL书写格式
					'success_url'=>'jy_msgorder/fuwu.order/',
					'error_url'=>'jy_msgorder/fuwu.order/',
			);
			$payid=cfc('pay')->create_pay_order($params);
			$this->pdo_update('order',array('pay_id'=>$payid),array('id'=>$id));
			$res=array(
				'pay_id'=>$payid,
				'order_id'=>$id,
			);
			exi($res);
	}else{
		
	}
	exi('提交成功！','','goback');
}
if($_RQ['op']=='payresult'){
	$payresult=$_SESSION['pay_result'];
	if(!$payresult){
		exi('支付失败，未收到支付结果！','error','main');
	}
	if($payresult['status']!=1){
		exi('支付失败！','error','main');
	}
	$order=pdo_get('jy_msgorder_order',array('id'=>$payresult['id'],'uniacid'=>$_SESSION['uniacid']));
	if(!$order){
		exi('支付失败！指定订单不存在！','error');
	}
	if($order['status']){
		exi('订单已支付，无需重复支付！','error');
	}
	if($order['payfee']!=$payresult['fee']){
		exi('支付失败！订单金额不匹配！','error');
	}
	$this->model('model')->payresult($order,$payresult,1);
	$this->model('notice')->notice_fuwuorder($order);	
	exi('支付成功','success','jy_msgorder/fuwu.order/list/status=1&id='.$order['id']);
}	
?>